<?

//Data loading
$title='LEMBAR INFORMASI PEKERJAAN (LIB)';
if (GetParam("office","")) $perush = GetCompany (GetParam("office",""));
else $perush = 'PT. MASAJI PRAYASA CARGO';

$page   = 'PAGE';
$jo_id = GetParam("jo_id","");
$TableName = "tbljoborder";


$DEFINE_FONT=0;
$pdf=new PDFReport('P',"mm","Letter");
$pdf->AddPage();
//$Result = GridList ("", "", "");
//if ($Result) $pdf->GridTable($Result);
$pdf->Output();



class PDFReport extends PDF {
    	
	function Header() {
  	  global $title,$perush,$page,$DEFINE_FONT,$ROOT_IMG_DIR, $jo_id,$DBConnection,$DBGeneral,$TableName;
            
  	  if ($DEFINE_FONT==0) {
  		 $this->AddFont('arialn','','arialn.php');
  		 $DEFINE_FONT=1;
  	  }
	  
	  $cbt_idr = 0;
	  $cbt_usd = 0;
	  $cat_idr = 0;
	  $cat_usd = 0;
	  
	  
      //Fetch Data Job Order
      
      $SQLJO = "SELECT *, c.nama as staff_marketing, e.nama as staff_operasional
                    FROM ".$TableName." as a
                    JOIN tblproject as b ON a.project_id = b.project_id
                    JOIN ".$DBGeneral.".tblstaff as c ON a.staff_id = c.staff_id
                    JOIN tbldebtur as d ON a.debtur = d.CUCODE
                    LEFT JOIN ".$DBGeneral.".tblstaff as e ON a.staff_jo_costing_id = e.staff_id
                    WHERE a.jo_id ='".$jo_id."' ORDER BY a.jo_id ASC";

      $ResultJO  = $DBConnection->dbc->get_results($SQLJO,ARRAY_A); 
      
	  //Fetch Data Cargo
      
      $SQLGridCargo = "SELECT * FROM tbljocargo as a
                       LEFT JOIN tblcargotype as b on a.cargo_type = b.cargo_id 
                       WHERE a.jo_id ='".$jo_id."' ORDER BY a.cargo_id";
                       
      $ResultGridCargo  = $DBConnection->dbc->get_results($SQLGridCargo,ARRAY_A); 
      
      //Fetch Data Activity
	  
      $SQLGridJobCosting =  "SELECT *, e.nama as staff_paid_to, f.nama as verifikator_name FROM tbljoborder_costing a
                    JOIN tblservices b ON a.services_id = b.services_id
                    JOIN tblactivity_setup c ON a.activities_id = c.act_nr_id
                    LEFT JOIN tbldebtur d ON a.paid_to_code = d.CUDEBTUR_FIN
                    LEFT JOIN ".$DBGeneral.".tblstaff as e ON a.paid_to_code = e.nik
					LEFT JOIN ".$DBGeneral.".tblstaff as f ON a.verifikator = f.nik
                    WHERE a.jo_id = $jo_id ORDER BY jo_costing_id ASC";

      $ResultJobCosting  = $DBConnection->dbc->get_results($SQLGridJobCosting,ARRAY_A);
	  
	  list($year1,$month1,$day1) = explode("-",$ResultJO[0]['jo_date']);
      $jo_date  = "$day1/$month1/$year1";
	  
	        
      $this->SetFont('arialn','',10);
	  
	  $this->Image($ROOT_IMG_DIR.'/flag_SI.jpg',12,11,34,20,'JPG');	  
	  $this->Cell(40,20,"",1,0,'C',0);
	  $this->SetFont('arialn','',18);
	  $this->Cell(110,20,"JOB ORDER COSTING",1,0,'C',0);
	  
	  $this->SetFont('arialn','',20);
	  $this->Cell(40,20,"",1,0,'C',0);	  	  
	  $this->SetFont('arialn','',10);
	  
	  $this->Ln();	  
	  
	  $this->Cell(190,5,"JOB ORDER : ".$ResultJO[0]['jo_code'],1,0,'C',0);
	      
      $this->Ln();
      $this->Ln();
       
      //Text Form
      $this->Cell(30,5,"Document Reference",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(135,5,$ResultJO[0]['doc_ref'],0,0,'L',0);
      $this->Ln();
      $this->Cell(30,5,"Project Name",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(135,5,$ResultJO[0]['project_name'],0,0,'L',0);
      $this->Ln();
      $this->Cell(30,5,"Customer",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(135,5,$ResultJO[0]['CUNAME'],0,0,'L',0);
      $this->Ln();
      $this->Cell(30,5,"Job Order Staff",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(135,5,$ResultJO[0]['staff_marketing'],0,0,'L',0);
      $this->Ln();
      $this->Cell(30,5,"Job Order Date",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(135,5,$jo_date,0,0,'L',0);
      $this->Ln();
      $this->Cell(30,5,"BL no.",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(135,5,$ResultJO[0]['bl_no'],0,0,'L',0);
      $this->Ln();
      $this->Cell(30,5,"Invoice no.",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(135,5,$ResultJO[0]['invoice_no'],0,0,'L',0);
      $this->Ln();
      $this->Cell(30,5,"Vessel",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(135,5,$ResultJO[0]['vessel'],0,0,'L',0);
      $this->Ln();
      $this->Cell(30,5,"JO Costing Staff",0,0,'L',0);
      $this->Cell(5,5,":",0,0,'C',0);
      $this->Cell(135,5,$ResultJO[0]['staff_operasional'],0,0,'L',0);
      $this->Ln();
      
      $this->Ln();
      
      //CARGO TYPE      
      $this->SetFont('arialn','',10);
      $this->Cell(50,5,"Cargo Type",1,0,'C',0);
      $this->Cell(30,5,"Quantity",1,0,'C',0);
      $this->Cell(30,5,"Weight (Kg)",1,0,'C',0);
      $this->Cell(30,5,"Volume (Cbm)",1,0,'C',0);
      $this->Cell(50,5,"Remarks",1,0,'C',0);
      $this->Ln();
      
      $this->SetFont('arialn','',9);
	  
	  if(!empty($ResultGridCargo))
      {
		  foreach($ResultGridCargo as $idx => $val)
		  {
			  $this->Cell(50,5,$val['cargo_name'],1,0,'C',0);
			  $this->Cell(30,5,$val['cargo_jumlah'],1,0,'C',0);
			  $this->Cell(30,5,$val['cargo_berat'],1,0,'C',0);
			  $this->Cell(30,5,$val['cargo_volume'],1,0,'C',0);
			  $this->Cell(50,5,$val['cargo_lamp'],1,0,'C',0);
			  $this->Ln();
		  }
		  
		  $this->Ln();
		  
      }
       
      //SERVICES ACTIVITY 
      $this->SetFont('arialn','',10);            
      $this->Cell(95,7,"ACTIVITY",1,0,'C',0);
	  $this->Cell(55,7,"SERVICES",1,0,'C',0);
      $this->Cell(40,7,"TOTAL COST AMOUNT",1,0,'C',0);      
      $this->Ln();
      
      $this->SetFont('arialn','',9);
	  
	  
	  $x = $this->GetX();
	  $y = $this->GetY();
	  $i = 0;
	  
	  if(!empty($ResultJobCosting))
      {
		  foreach($ResultJobCosting as $idx2 => $val2)
		  {
			  //$this->Cell(95,7,$val2['actname'],1,0,'C',0);
			  $y1 = $this->GetY();
			  $this->MultiCell(95, 7, $val2['actname'], 'LRB');	
			  $y2 = $this->GetY();
			  $yH = $y2 - $y1;
						
			  $this->SetXY($x + 95, $this->GetY() - $yH);
			  
			  $this->Cell(55,$yH,$val2['services_name'],1,0,'C',0);			  
			  $this->Cell(40,$yH,number_format($val2['total_amount'],2),1,0,'C',0); 
			  $this->Ln();
			  
			  if($val2['curr'] == "IDR")
			  {
				  $cbt_idr+= $val2['amount'];
				  $cat_idr+= $val2['total_amount'];
			  }
			  
			  else if($val2['curr'] == "USD")
			  {
				  $cbt_usd+= $val2['amount'];
				  $cat_idr+= $val2['total_amount'];	  			  
			  }
			      
		  }
		  
		  $this->Ln();
		  
      }
	    
	  
	        
	  //END GRID
      
         
     
	}

	

	function Footer() {
	    //Closure line
	    //$this->Cell(180,0,'','T');
	}

}


?>
